package classespinkpony.validators
{
	import mx.validators.Validator;
	import mx.validators.ValidationResult;
	
	public class PasswordValidator extends Validator
	{
		private var results:Array;
		
		public function PasswordValidator(){
			super();
		}
		
		public var confirmationSource: Object;
		public var confirmationProperty: String;
		public var noMatchError:String;
		
		override protected function doValidation(value:Object):Array {
			
			var results:Array = super.doValidation(value.password);
			
			if (value.password != value.confirmation){
				results.push(new ValidationResult(true, null, "Mismatch", noMatchError));
			}
			
			return results;
		}       
		
		override protected function getValueFromSource():Object
		{
			var value:Object = {};			
			value.password = super.getValueFromSource();
			
			if (confirmationSource && confirmationProperty){
				value.confirmation = confirmationSource[confirmationProperty];
			}
			
			return  value;
		}               
	}
}